package com.hgz.ssmdemo.common.exceptions;


import com.hgz.ssmdemo.common.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;



@RestControllerAdvice("com.hgz.ssmdemo.web.controller")
@Slf4j
public class GlobalExceptionAdvice {

//    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionAdvice.class);


    @ExceptionHandler(GlobalException.class)
    public ResultVO handleGlobalException(GlobalException e) {
        log.error(e.getMessage(), e);
        ResultVO vo = new ResultVO();
        vo.setCode(e.getErrorCode());
        vo.setMessage(e.getMessage());
        return vo;
    }

    @ExceptionHandler(Exception.class)
    public ResultVO handleGlobalException(Exception e) {
        log.error(e.getMessage(), e);
        ResultVO vo = new ResultVO();
        vo.setCode(500);
        vo.setMessage("服务器繁忙，请稍后尝试");
        return vo;
    }
}